package com.casework

import grails.plugin.spock.UnitSpec
import static com.casework.CompetitionConcern.*
import spock.lang.Unroll

class LegalCaseSpec extends UnitSpec {

    @Unroll("Competition concern should say #competitionConcern")
    def "Competition Concern is calculated correctly"() {
        given:
        def legalCase = new LegalCase()
        mockDomain LegalCase, [legalCase]

        when:
        measures.each { measure ->
            legalCase.addToMeasures(measure)
        }

        then:
        legalCase.competitionConcern == competitionConcern

        where:
        measures                                | competitionConcern
        []                                      | "Unclassified as no Measure"
        createConcern([Horizontal])             | Horizontal.toString()
        createConcern([Vertical])               | Vertical.toString()
        createConcern([Horizontal, Vertical])   | Mixed.toString()
        createConcern([Horizontal, Horizontal]) | Horizontal.toString()
        createConcern([Vertical, Vertical])     | Vertical.toString()
    }

    @Unroll('Article should say #expectedArticle')
    def 'Calculate article'() {
        given:
        def legalCase = new LegalCase()
        mockDomain LegalCase, [legalCase]

        when:
        legalCase.phase = phase

        then:
        legalCase.article == expectedArticle

        where:
        phase | expectedArticle
        null  | ''
        1     | '6(1)(b)'
        2     | '8(2)'
    }

    private List createConcern(items) {
        List concerns = []
        items.each {
            concerns << new Measure(competitionConcern: it)
        }
        return concerns
    }
}
